package com.jackrain.clouddata.sys.Listenter;

import com.alibaba.fastjson.JSONArray;
import com.jackrain.clouddata.oms.dao.RetSaleApplyDao;
import com.jackrain.clouddata.oms.dao.RetSaleDao;
import com.jackrain.nea.exception.NDSException;
import com.jackrain.nea.util.ApplicationContextHandle;
import com.jackrain.nea.web.query.QueryEngine;
import com.jackrain.util.WebUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Component("com.jackrain.clouddata.sys.Listenter.RetSaleApplyMessageProcess")
@Slf4j
public class RetSaleApplyMessageProcess implements MessageProcess {
    public RetSaleApplyMessageProcess(){ }

    @Override
    public void process(Object paramObject, String tag) throws Exception{
        JSONArray paramArray = JSONArray.parseArray(paramObject.toString());
        RetSaleApplyDao retSaleApplyDao = ApplicationContextHandle.getBean(RetSaleApplyDao.class);
        try{
            Long ad_client_id = (Long)QueryEngine.getInstance().doQueryOne("SELECT AD_CLIENT_ID FROM OMS_TAG WHERE TAGNAME = ?", new Object[]{tag});
            if (null == ad_client_id || "".equals(ad_client_id)) {
                throw new NDSException("公司ID未找到!");
            }
            for (int i =0;i< paramArray.size();i++) {
                retSaleApplyDao.update(paramArray.getJSONObject(i), tag,ad_client_id);
                WebUtils.CallInterface(ad_client_id,"OMS_M_RET_SALE_APPLY",tag,paramArray.getJSONObject(i));
            }

        }catch(Exception e){
            throw e;
        }

    }

}
